package com.wocao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wocao.controller.SysDictDataController;
import com.wocao.entity.*;
import com.wocao.entity.ZyRoom;
import com.wocao.mapper.ZyRoomMapper;
import com.wocao.service.ZyRoomService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wocao.utils.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 房间  服务实现类
 *
 * @since 2023-12-03
 */
@Service
public class ZyRoomServiceImpl extends ServiceImpl<ZyRoomMapper, ZyRoom> implements ZyRoomService {

    @Autowired
    private ZyRoomMapper zyRoomMapper;

    @Override
    public Page<ZyRoom> getRoomsByLike(Page<ZyRoom> zyRoomPage, String buildingId, String unitId, String roomStatus, String communityId) {
        return zyRoomMapper.selectRoomsByLike(zyRoomPage, buildingId, unitId, roomStatus, communityId);
    }

    @Override
    public void export(HttpServletResponse response, String[] roomIds) throws IOException {

        List<ZyRoom> zyRooms = new ArrayList<>();
        for (int i = 0; i < roomIds.length; i++) {
            ZyRoom zyRoom = zyRoomMapper.selectById(roomIds[i]);
            zyRooms.add(zyRoom);
        }
        ExcelUtil.export(response, ZyRoom.class, zyRooms);
    }

    @Override
    public List<Building> getBuildingAndUnit() {
        return zyRoomMapper.selectBuildingAndUnit();
    }

    @Override
    public List<ZyRoom> getRoomsByBuildingId(String unitId) {
        LambdaQueryWrapper<ZyRoom> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ZyRoom::getUnitId, unitId);
        return zyRoomMapper.selectList(queryWrapper);
    }


}
